# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=dbus
pkgver=1.14.0
pkgrel=1
pkgdesc="Freedesktop.org message bus system"
url="https://www.freedesktop.org/Software/dbus"
arch="all"
license="AFL-2.1 OR GPL-2.0-or-later"
depends_dev="util-linux-dev"
makedepends="$depends_dev
	autoconf
	autoconf-archive
	automake
	expat-dev
	glib-dev
	libsm-dev
	libtool
	libx11-dev
	xmlto
	"
checkdepends="xvfb-run"
pkggroups="messagebus"
install="$pkgname.pre-install $pkgname.post-install"
triggers="$pkgname.trigger=/usr/share/dbus-1/system.d"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-doc
	$pkgname-libs
	$pkgname-x11
	$pkgname-openrc
	"
source="https://dbus.freedesktop.org/releases/dbus/dbus-$pkgver.tar.xz
	0001-build-Treat-with-x-yes-the-same-as-with-x-auto.patch
	0002-Move-DBUS_X_-definitions-into-PKG_CHECK_MODULES-bloc.patch
	0003-Emit-an-error-when-with-x-was-given-but-no-X11-libs-.patch
	0004-Add-have_x11-no-if-without-x-was-given-to-make-later.patch
	0005-Convert-if-calls-to-AS_IF-macro-for-the-block-that-h.patch
	$pkgname.initd
	$pkgname.confd
	"
options="!check"  # introduces circular dependency with xorg-server (xvfb-run -> xvfb)

# secfixes:
#   1.12.18-r0:
#     - CVE-2020-12049
#   1.12.16-r0:
#     - CVE-2019-12749

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--with-xml=expat \
		--with-dbus-user=messagebus \
		--with-system-pid-file=/run/dbus/dbus.pid \
		--disable-verbose-mode \
		--enable-inotify \
		--disable-dnotify \
		--enable-modular-tests=yes \
		--disable-asserts \
		--enable-user-session \
		--enable-xml-docs \
		--with-session-socket-dir=/tmp \
		--with-x
	make
}

check() {
	xvfb-run make check
}

package() {
	make -j1 DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/lib/systemd

	install -Dm755 "$srcdir"/dbus.initd "$pkgdir"/etc/init.d/dbus
	install -Dm644 "$srcdir"/dbus.confd "$pkgdir"/etc/conf.d/dbus
}

libs() {
	pkgdesc="D-BUS access libraries"
	replaces="dbus"

	amove usr/lib/lib*.so.*
}

x11() {
	pkgdesc="X11 add-ons for D-BUS"
	depends="dbus=$pkgver-r$pkgrel"

	amove usr/bin/dbus-launch
}

sha512sums="
9bf17a3ebb3cf44722c6fbf24ee56e9dc14d6882fc312f26c7f07459d969424bc2fb63a229139e011804ecc479a8f0eb1a0c83286f8d5a664c5979d12634179f  dbus-1.14.0.tar.xz
d7c9ca341af0672621b3793ae51118d1b3ab4d1cd4cb8f8ad6b209e713c8e6446c2641c250ba82be42bb5ad3b7812e85165315a0997e4e298c8f8a265cbdcb3a  0001-build-Treat-with-x-yes-the-same-as-with-x-auto.patch
6e8cdbef3c4263d9a2a878cbbc09511c68a02bc9b16d4d7e3a5e39e07e8dce9ec25ce5c7a7c77bda89e7a2af93246d5cbfd503406acb082d8189936c7d6076dd  0002-Move-DBUS_X_-definitions-into-PKG_CHECK_MODULES-bloc.patch
eb53caf763fa11d2d9be6e9a4a09e93ea021d1764f401fb3d18f4ef656efacfda231efe2618adb704d15d881846785fea266c1d9700adc3cb38792cee823cf34  0003-Emit-an-error-when-with-x-was-given-but-no-X11-libs-.patch
20163c93695c4286f3634941e959dc3b1289ab8d056d528ed35ccb7e71c5706377f72d514f9609bf5f51e9f573b9a996c64631bd2079ad12ae7cf0b2e69f227f  0004-Add-have_x11-no-if-without-x-was-given-to-make-later.patch
723ba846da40883d7b1d2fd6e48822b427a5f29e9530854e90f2d761cbba711711b3013ed2b824576cdc529726c7bb39f8a5c9cc779222efb8e016c5d9d18332  0005-Convert-if-calls-to-AS_IF-macro-for-the-block-that-h.patch
0db5c0804b5aa19c8d7e517b1c6d11b9b52d96477d4d26769c01a31765491ff12897b5634455ee57d978ea30e2d71c5df5ed3eecd5435983d8ab1128ff516315  dbus.initd
3f063efa672a900ed04bc7224ba31b3ced91bb98ae096a3ce12552a0b6e2c38ddb445edb4876518f9be4140a5d901dc62080e95aab4346d89dbf329ebec33cb3  dbus.confd
"
